<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item>
        <el-radio-group
          v-model="queryParams.exportParam"
          size="small"
          fill="#66b1ff"
          @change="changeState"
        >
          <el-radio
            :label="'personal'"
            v-hasPermi="['product:internalOrder:myList']"
            >我的申请</el-radio
          >
          <!-- <el-radio
            :label="'depart'"
            v-hasPermi="['product:sampleApply:deplist']"
            >部门记录</el-radio
          > -->
          <el-radio :label="'all'" v-hasPermi="['product:internalOrder:query']"
            >所有记录</el-radio
          >
        </el-radio-group>
      </el-form-item>
      <!--  -->

      <div>
        <el-form-item label="" prop="applyStatus">
          <el-radio-group
            v-model="queryParams.applyStatus"
            size="small"
            @change="changeTheme"
            fill="#66b1ff"
          >
            <el-radio :label="null">所有状态</el-radio>
            <el-radio :label="'to_apply'">待提交申请</el-radio>
            <el-radio :label="'dingding_approval'">待钉钉审核</el-radio>
            <el-radio :label="'shipped_ready'">待发货</el-radio>
            <el-radio :label="'shipped'">已发货</el-radio>
            <el-radio :label="'afterstate'">售后</el-radio>
          </el-radio-group>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="时间筛选" prop="dataDate">
          <el-date-picker
            key="daterange"
            v-model="rangeDate"
            type="daterange"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="{
              disabledDate: (time) =>
                !(
                  time.getTime() >= Date.now() - 365 * 8.64e7 &&
                  time.getTime() < Date.now()
                ),
            }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width: 240px"
            @change="handleChange"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="" prop="createBy">
          <el-input
            v-model="queryParams.createBy"
            placeholder="申请人"
            clearable
            @keyup.enter.native="changeTheme"
          />
        </el-form-item>

        <el-form-item>
          <!-- <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        > -->
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:internalOrder:add']"
          >新增</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:internalOrder:edit']"
          >修改</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:internalOrder:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:internalOrder:exportExcel']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          size="mini"
          @click="handlestartApply"
          v-hasPermi="['product:internalOrder:startApply']"
          >拍下订单</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          size="mini"
          @click="handlesubmitApply"
          v-hasPermi="['product:internalOrder:submitApply']"
          >提交订单</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleApplyExcel"
          >导出申请表</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          size="mini"
          @click="handlecheckDingdingStatus"
          v-hasPermi="['product:internalOrder:checkDingdingStatus']"
          >检测钉钉状态</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" @click="handlestartApplyFlow"
          >提交内购申请</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" plain @click="handleopenSample"
          >我要换货</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          size="mini"
          @click="Visibleapply = true && ids.length > 0"
          v-hasPermi="['product:internalOrder:addComment']"
          >追加评论</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          size="mini"
          plain
          @click="handlecheckOutOfStock"
          v-hasPermi="['product:apply:checkOutOfStock']"
          >售后检测</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div ref="tableDom">
      <el-table
        :maxHeight="newList.length ? tableHeight : 'auto'"
        :data="newList"
        @selection-change="handleSelectionChange"
        @row-dblclick="t"
        @cell-click="tableEdit"
        :cell-class-name="tableCellClassName"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="内部订单ID"
          width="150"
          align="center"
          prop="id"
        />
        <el-table-column label="申请人ID" align="center" prop="createBy" />
        <!-- <el-table-column
          width="130"
          label="申请人"
          align="center"
          prop="createBy"
        /> -->
        <el-table-column
          label="申请人姓名"
          align="center"
          prop="applicantName"
        />
        <el-table-column
          width="180"
          label="申请时间"
          align="center"
          prop="createTime"
        />
        <el-table-column label="订单状态" align="center" prop="applyStatus">
          <template slot-scope="scope">
            <div>
              {{ scope.row.applyStatus | state2 }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column label="支付截图" align="center" prop="paymentUrl" /> -->
        <el-table-column
          width="140"
          label="支付截图"
          align="center"
          prop="paymentUrl"
          ><template slot-scope="scope">
            <image-preview
              :src="scope.row.paymentUrl"
              :width="40"
              :height="40"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="购买商品件数"
          align="center"
          prop="productNum"
        />
        <el-table-column
          label="购买商品金额"
          align="center"
          prop="purchaseAmount"
        />
        <el-table-column label="运费金额" align="center" prop="shippingFee" />
        <el-table-column label="汇总金额" align="center" prop="totalAmount" />

        <!-- <el-table-column
        width="130"
        label="更新者"
        align="center"
        prop="updateBy"
      />
      <el-table-column
        width="180"
        label="更新时间"
        align="center"
        prop="updateTime"
      /> -->
        <el-table-column
          width="180"
          label="申请理由"
          align="center"
          prop="applyReason"
        />
      </el-table>
    </div>
    <!-- v-if="internalOrderList.length > 3" -->
    <el-divider @click="showAll = !showAll">
      {{ showAll ? "收起" : "展开" }}
      <i :class="'el-icon-arrow-' + showAll ? 'up' : 'down'"></i>
    </el-divider>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="pageList"
    />

    <!-- 添加或修改内购申请订单对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
      v-if="open"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="申请理由" prop="applyReason">
          <el-input v-model="form.applyReason" placeholder="请输入申请理由" />
        </el-form-item>
        <el-form-item label="支付截图" prop="logoPosition">
          <el-upload
            ref="uploadlogoPosition"
            :action="imgUpload.url"
            :headers="imgUpload.headers"
            list-type="picture-card"
            :on-change="changelogoPosition"
            :file-list="filelogoPosition"
            multiple
            :on-success="uploadlogoPosition"
            :on-remove="Removelogourl"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
          <div id="preview" @paste="handlelogoPosition">
            <span
              ><i class="el-icon-s-opportunity" style="color: #fb894c"></i
              >点击此处 将图片按Ctrl+V 粘贴至此处</span
            >
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      title="我要换货"
      :visible.sync="isopenSample"
      append-to-body
      width="90%"
      v-if="isopenSample"
    >
      <Handle
        :ids="ids"
        @handleColse="handleColse"
        :OrderDetailsList="OrderDetailsList"
      />
    </el-dialog>

    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      title="追加评论"
      :visible.sync="Visibleapply"
      append-to-body
      width="500px"
      v-if="Visibleapply"
    >
      <el-form
        ref="formApply"
        :model="formApply"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="用户ID" prop="userID">
          <!-- <el-input v-model="formApply.remark" placeholder="申请理由" /> -->
          <el-input v-model="formApply.userID" placeholder="用户ID" />
        </el-form-item>
        <el-form-item label="申请理由" prop="reason">
          <!-- <el-input v-model="formApply.remark" placeholder="申请理由" /> -->
          <el-input
            v-model="formApply.reason"
            placeholder="请输入申请理由"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 12 }"
            :style="{ width: '100%' }"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: 50px">
        <el-button type="primary" @click="handleaddComment">确 定</el-button>

        <!-- <el-button @click="cancelApply">取消</el-button> -->
      </div>
    </el-dialog>

    <apply :templateId="Params.templateId" style="margin-top: 15px" />
  </div>
</template>

<script>
import apply from "@/views/internal/apply/index.vue";
import Handle from "@/views/internal/Handle";
import {
  listApply,
  getApply,
  delApply,
  addApply,
  updateApply,
  checkOutOfStock,
} from "@/api/internal/apply";
import {
  listInternalOrder,
  getInternalOrder,
  delInternalOrder,
  addInternalOrder,
  updateInternalOrder,
  startApply,
  submitApply,
  exportExcel,
  startApplyFlow,
  checkDingdingStatus,
  myList,
  addComment,
  getOrderDetails,
} from "@/api/internal/internalOrder";
import { tansParams, blobValidate } from "@/utils/ruoyi";
import cache from "@/plugins/cache";
import moment from "moment";
//--------导入token
import { getToken } from "@/utils/auth";
import { getInfo } from "@/api/login.js";
export default {
  name: "InternalOrder",
  components: {
    Handle,
    apply,
  },

  data() {
    return {
      OrderDetailsList: [],
      rangeDate: [],
      tableHeight: "",
      //追加评论
      Visibleapply: false,
      formApply: {},
      //换货
      isopenSample: false,

      //待提交申请禁用
      to_sumbit: false,
      applyname: "",

      //选中get
      to_apply: [],
      list: [],
      username: [],

      applytotal: 0,
      applyList: [],
      showAll: false, //展开与收起布尔值

      pjtUrl: process.env.VUE_APP_BASE_API,
      // 图片数量限制
      limit: 2,
      //logo相对路径
      logoUrl: "",
      //页面上存的暂时logo图片地址List
      // fileList: [{ url: "" }],
      filelogoPosition: [],
      //图片地址
      imageUrl: "",
      dialogVisible: false,
      imgUpload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 内购申请订单表格数据
      internalOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        paymentUrl: null,
        exportParam: "personal",
        applyStatus: null,
        beginTime: null,
        endTime: null,
        createBy: null,
      },
      Params: {
        pageNum: 1,
        pageSize: 10,
        templateId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  filters: {
    state1(string) {
      if (string == "note") {
        return "笔记";
      }
      if (string == "live") {
        return "直播";
      }
      if (string == "VFU") {
        return "VFU";
      }
      // if (int == 2) { return "审批通过" };
    },
    /***
    一级二级增加售后状态
字段：applyStatus,状态值有3
1、待认领达人 -可以修改产品信息 status:to_match
2、待提交售后  --可修改达人信息，不能修改产品信息status:to_apply
3、已售后  --不可修改任意信息status:applyed 
1、所有，默认，不带参数。
2、待提交申请--to_apply
3、待钉钉审核--dingding_approval
4、已发货--shipped
5、售后--afterstate
    ** */
    state2(string) {
      if (string == "to_exchange") {
        return "待换货";
      }
      if (string == "to_apply") {
        return "待提交申请";
      }
      if (string == "dingding_approval") {
        return "待钉钉审核";
      }
      if (string == "supervisor_approval") {
        return "待审核";
      }
      if (string == "dingding_approved") {
        return "已审核";
      }
      if (string == "product_supervisor") {
        return "待产品中心经理审核";
      }
      if (string == "manage_approval") {
        return "待经理审核";
      }
      if (string == "commodity_approval") {
        return "待商品部审核";
      }
      if (string == "shipped_ready") {
        return "待发货";
      }
      if (string == "shipped") {
        return "已发货";
      }
      if (string == "afterstate") {
        return "售后";
      }
      if (string == "to_signed") {
        return "待签收";
      }
      if (string == "signed") {
        return "已签收";
      }
      if (string == "to_returned") {
        return "待退货";
      }
      if (string == "returning") {
        return "退货中";
      }
      if (string == "returned") {
        return "已退样";
      }
      if (string == "part_returned") {
        return "部分退样";
      }
      if (string == "not_return") {
        return "不归还";
      }
      if (string == "cancel_return") {
        return "未收到";
      }
      if (string == "end") {
        return "结束";
      }
      if (string == "canceled") {
        return "已取消";
      }
      // if (int == 2) { return "审批通过" };
    },
  },
  created() {
    this.getroles();
    this.getList();
  },
  mounted() {
    var _this = this;
    this.resizeTable();
    window.onresize = function () {
      _this.resizeTable();
    };
  },
  //记得清空  如果在keepalive中 则使用activated  deactivated
  destroyed() {
    window.onresize = null;
  },
  computed: {
    newList() {
      //先判断showAll的布尔值，第一次进来默认为false
      if (this.showAll === false) {
        // 判断数组长度是否大于3
        if (this.internalOrderList.length > 3) {
          // 截取前3条数据，返出去展示
          return this.internalOrderList.slice(0, 3);
        } else {
          // 如果列表长度不够三条，直接展示原列表
          return this.internalOrderList;
        }
      } else {
        //这里showAll为true时，展示全部数据，对应名称图标更改
        return this.internalOrderList;
      }
    },
  },
  methods: {
    tableCellClassName({ column, columnIndex }) {
      // return "font-weight: bold;";
      if (column.label === "汇总金额") {
        return "highlight-row";
      } else {
        return "";
      }
    },
    //售后检测
    handlecheckOutOfStock() {
      this.openLoading2();
      checkOutOfStock().then((response) => {
        this.$modal.closeLoading();
        if (response.code == 200) {
          this.$modal.msgSuccess("检测通过");
        }
      });
    },
    //时间选择
    handleChange() {
      this.queryParams.beginTime = this.rangeDate[0];
      this.queryParams.endTime = moment(this.rangeDate[1]).format(
        "YYYY-MM-DD 23:59:59"
      );
      this.queryParams.pageNum = 1;
      if (this.queryParams.exportParam == "personal") {
        this.getList();
      } else if (this.queryParams.exportParam == "all") {
        //公司所有
        this.getAllList();
      }
    },
    // table自动高度
    returnTableHeight(ref, bottomOffset) {
      let height = null;
      height =
        window.innerHeight - ref.getBoundingClientRect().top - bottomOffset;
      return height;
    },
    resizeTable() {
      this.$nextTick(() => {
        this.tableHeight = this.returnTableHeight(this.$refs.tableDom, 100);
      }, 0);
    },
    handleopenSample() {
      if (this.ids.length != 1) {
        return;
      }
      getOrderDetails(this.ids).then((response) => {
        if (response.code == 200 && response.data.length > 0) {
          this.OrderDetailsList = response.data;
          // setTimeout(() => {
          this.isopenSample = true;
          // }, 1000);
        } else {
          this.isopenSample = false;
        }
      });
    },
    handleColse() {
      this.isopenSample = false;
      // this.getList();
    },
    getroles() {
      // var userId = null
      getInfo().then((res) => {
        console.log(JSON.stringify(res));
        this.applyname = res.user.dept.deptName + "-" + res.user.nickName;
        console.log(JSON.stringify(this.applyname));
      });
    },
    handlecheckDingdingStatus() {
      if (this.ids.length <= 0) {
        this.$modal.msgError("请选择数据");
      }
      this.openLoading2();
      checkDingdingStatus(this.ids)
        .then((response) => {
          this.$modal.closeLoading();
          if (response.code == 200) {
            this.$modal.msgSuccess("钉钉检测通过");
            return;
            this.handlestartApplyFlow();
          } else {
            this.$modal.msgError("钉钉检测不通过");
          }
        })
        .catch((err) => {
          // 异步操作出错也关闭加载
          this.$modal.closeLoading();
        });
      return;
      if (this.to_apply.length == 1 && this.to_apply[0] == "to_apply") {
        if (this.username.length == 1 && this.username[0] == this.applyname) {
          // this.Visibleapply = true;
        } else {
          // this.Visibleapply = false;
          this.$modal.msgError("请选择本人申请记录信息！");
          return;
        }
      } else {
        // this.Visibleapply = false;
        this.$modal.msgError("订单处于 “非待提交申请”状态，暂不可申请。");
        return;
      }
    },
    // 追加评论
    handleaddComment() {
      //    idList;  （勾选某一条记录后，弹窗填入以下两个参数）
      // private Long userID;
      // private String reason;
      let obj = {
        idList: this.ids,
        userID: Number(this.formApply.userID),
        reason: this.formApply.reason,
      };
      this.openLoading();
      addComment(obj)
        .then((response) => {
          this.$modal.closeLoading();
          this.Visibleapply = false;
          if (response.code == 200) {
            this.$modal.closeLoading();
            this.$modal.msgSuccess("已追加评论");
            this.getList();
          }
        })
        .catch((err) => {
          // 异步操作出错也关闭加载
          this.$modal.closeLoading();
        });
    },
    handlestartApplyFlow() {
      this.openLoading1();
      startApplyFlow(this.ids)
        .then((response) => {
          this.$modal.closeLoading();
          if (response.code == 200) {
            this.$modal.closeLoading();
            this.$modal.msgSuccess("申请成功");
            this.getList();
          }
        })
        .catch((err) => {
          // 异步操作出错也关闭加载
          this.$modal.closeLoading();
        });
    },
    //单击
    tableEdit(row, column, cell, event) {
      this.Params.templateId = row.id ? row.id.toString() : "";
      console.log(this.Params.templateId);
      return;
      listApply(this.Params).then((response) => {
        this.applyList = response.rows;
        this.applytotal = response.total;
        // this.openApply = true;
      });
    },
    pageList() {
      if (this.queryParams.exportParam == "personal") {
        this.getList();
      } else if (this.queryParams.exportParam == "all") {
        //公司所有
        this.getAllList();
      }
    },
    // 打开加载层
    openLoading2() {
      this.$modal.loading("正在检测，请稍候！");
    },
    // 打开加载层
    openLoading1() {
      this.$modal.loading("正在申请，请稍候！");
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载，请稍候！");
    },
    handlestartApply() {
      this.openLoading();
      startApply(this.ids).then((response) => {
        this.$modal.closeLoading();
        if (response.code == 200) {
          this.getList();
        }
      });
    },
    handlesubmitApply() {
      this.openLoading();
      submitApply(this.ids).then((response) => {
        this.$modal.closeLoading();
        if (response.code == 200) {
          this.getList();
        }
      });
    },
    //点击某一行
    t(row, column, cell, event) {
      console.log(row, column, cell, event);

      this.handleUpdate(row);
      if (row.createBy == this.applyname) {
        if (row.applyStatus != "to_apply") {
          this.open = false;
          this.$modal.msgError("订单暂不可修改。");
          return;
        } else {
          this.open = true;
        }
      } else {
        this.open = false;
        this.$modal.msgError("请选择本人申请记录信息！");
        return;
      }
    },
    changeState(val) {
      this.queryParams.pageNum = 1;
      if (this.queryParams.exportParam == "personal") {
        this.getList();
      } else if (this.queryParams.exportParam == "all") {
        //公司所有
        this.getAllList();
      }
    },
    //发货状态改变
    changeTheme(val) {
      console.log(val);
      this.queryParams.pageNum = 1;
      if (this.queryParams.exportParam == "personal") {
        this.getList();
      } else if (this.queryParams.exportParam == "all") {
        //公司所有
        this.getAllList();
      }
    },
    //
    getAllList() {
      this.loading = true;
      listInternalOrder(this.queryParams).then((response) => {
        this.internalOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
        if (this.internalOrderList.length > 0) {
          this.tableEdit(this.internalOrderList[0]);
        }
      });
    },

    /** 查询内购申请订单列表 */
    getList() {
      let obj = {
        pageNum: this.queryParams.pageNum,
        thisPageSize: this.queryParams.pageSize,
        exportParam: this.queryParams.exportParam,
        applyStatus: this.queryParams.applyStatus,
        beginTime: this.queryParams.beginTime,
        endTime: this.queryParams.endTime,
        createBy: this.queryParams.createBy,
      };
      // obj.thisPageSize=this.queryParams.pageSize

      this.loading = true;

      myList(obj).then((response) => {
        this.internalOrderList = response.data ? response.data : [];
        if (this.internalOrderList.length > 0) {
          this.tableEdit(this.internalOrderList[0]);
        } else {
          this.tableEdit({});
        }

        this.total = response.totalCount;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        paymentUrl: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.pageList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.rangeDate = [];
      this.queryParams.createBy = null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;

      var to_apply = selection.map((item) => item.applyStatus);
      console.log(JSON.stringify(to_apply));

      var username = selection.map((item) => item.createBy);
      console.log(JSON.stringify(username));
      this.username = Array.from(new Set(username));
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加内购申请订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getInternalOrder(id).then((response) => {
        this.logoUrl = response.data.paymentUrl;
        this.filelogoPosition = response.data.paymentUrl
          ? [{ url: process.env.VUE_APP_BASE_API + response.data.paymentUrl }]
          : []; //logo图片加的是这一行
        this.form = response.data;

        this.title = "修改内购申请订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.paymentUrl = this.logoUrl; // 注：重要(用于添加到数据库)，加的是这一行
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateInternalOrder(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInternalOrder(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除内购申请订单编号为"' + ids + '"的数据项？')
        .then(function () {
          return delInternalOrder(ids);
        })
        .then(() => {
          this.handleChange();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "product/internalOrder/exportExcel",
        {
          ...this.queryParams,
        },
        `internalOrder_${new Date().getTime()}.xlsx`
      );
    },
    //handlelogoPosition图片
    handlelogoPosition(event) {
      const items = (event.clipboardData || window.clipboardData).items;
      let file = null;
      if (!items || items.length === 0) {
        this.$message.error("当前浏览器不支持本地");
        return;
      }
      // 搜索剪切板items
      for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
          file = items[i].getAsFile();
          break;
        }
      }
      if (!file) {
        this.$message.error("粘贴内容非图片");
        return;
      }
      if (this.filelogoPosition.length >= this.limit) {
        this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`); // 图片数量超出
        return;
      }
      this.$refs.uploadlogoPosition.handleStart(file); // 将粘贴过来的图片加入预上传队列
      this.$refs.uploadlogoPosition.submit(); // 提交图片上传队列
    },
    //上传
    changelogoPosition(file, fileList) {
      // this.fileList = fileList
      console.log("成功", file, fileList);
      console.log(JSON.stringify(file));
      console.log(JSON.stringify(fileList));
      if (fileList.length > 1) {
        this.filelogoPosition = fileList.slice(-1);
      }
    },
    Removelogourl() {
      this.logoUrl = "";
    },

    uploadlogoPosition(res, file, fileList) {
      console.log(JSON.stringify(file.response.fileName));
      this.logoUrl = file.response.fileName;
    },
    handleApplyExcel() {
      // var apply = [];
      // this.list.forEach((item) => {
      //   apply.push({
      //     businessId: item.id,
      //     applyStatus: item.applyStatus,
      //     applyId: this.userId,
      //   });
      // });
      // // console.log();
      // // apply = JSON.stringify(apply);
      // exportExcel(this.ids).then((data) => {
      //   // return;
      //   const isBlob = blobValidate(data);
      //   if (isBlob) {
      //     const blob = new Blob([data]);
      //     saveAs(blob, "申请表");
      //   }
      // });
      this.download(
        "product/internalOrder/exportExcel",
        {
          ...this.queryParams,
        },
        // this.ids,

        // {
        // this.ids,
        // },
        // headers: {
        // header: { responseType: "blob" },

        // Authorization: "Bearer " + getToken(),
        // "Content-Type": "application/json",
        // },
        `申请表_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" >
/* 添加你想要的特定行的CSS样式 */
.highlight-row {
  position: sticky;
  bottom: 0;
  font-weight: bold;
}
</style>
<style scoped>
.el-divider__text.is-center {
  background-color: aquamarine;
  cursor: pointer;
}
.lists {
  width: 300px;
  margin: 20px 0;
}
.el-alert {
  margin: 10px 0;
}
</style>